package com.szrt.oa.role.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.szrt.oa.base.controller.BaseController;
import com.szrt.oa.role.entity.RoleEntity;
import com.szrt.oa.role.service.RoleService;

@Controller
@RequestMapping("/role")
public class RoleController extends BaseController<RoleEntity> {
	
	@Autowired
	private RoleService service;
	
	@Autowired
	private RoleEntity entity;
	
	
	//http://localhost:8090/super-base-ssm/role/myfind.do
	//http://localhost:8090/super-base-ssm/role/myfind.do
	@RequestMapping("/myfind")
	@ResponseBody
	public Map<String, Object> myfind(RoleEntity entity) {
		
		Map<String, Object> queryAll = service.queryAll();
		return queryAll;
	}
	
	//http://localhost:8090/super-base-ssm/role/mydelete?id=1
	//http://localhost:8090/super-base-ssm/role/mydelete
	@RequestMapping("/mydelete")
	@ResponseBody
	public Map<String, Object>  mydeleteByid(String did) {
		
		String[] split = did.split(",");
		Map<String, Object>  map=new HashMap<String,Object>();
		int counter=0;
		for (String s : split) {
			entity.setId(Integer.parseInt(s));
			Map<String, Object>  mydelete = service.deleteByid(entity);
			String code = (String)mydelete.get("code");
			if("200".equals(code)){
				counter++;
			}
		}
		//
		map.put("counter", counter);
		return map;
		
		/*Map<String, Object>  mydelete = service.deleteByid(entity);
		return mydelete;*/
	}
	
	//http://localhost:8090/super-base-ssm/role/myupdate?roleName=xx&id=3003
	@RequestMapping("/myupdate")
	@ResponseBody
	public Map<String, Object>  myupdate(RoleEntity entity) {
		
		Map<String, Object>  myupdate = service.update(entity);
		return myupdate;
	}
	
	//http://localhost:8090/super-base-ssm/role/myinsert.do?roleName=test管理
	//http://localhost:8090/super-base-ssm/role/myinsert.do
	@RequestMapping("/myinsert")
	@ResponseBody
	public Map<String, Object>  myinsert(RoleEntity entity) {
		
		Map<String, Object>  myinsert = service.insert(entity);
		return myinsert;
	}
	
	//http://localhost:8090/super-base-ssm/role/findPage?pageIndex=1&pageSize=4
	//http://localhost:8090/super-base-ssm/role/findPage
	@RequestMapping("/findPage")
	@ResponseBody
	public Map<String, Object>  findPage(int pageIndex,int pageSize) {
		
		Map<String, Object> map = service.queryByPage(pageIndex, pageSize);
		return map;
	}
	
	//http://localhost:8090/super-base-ssm/role/myquery?roleName=x
	//http://localhost:8090/super-base-ssm/role/myquery
	@RequestMapping("/myquery")
	@ResponseBody
	public Map<String, Object>  myquery(RoleEntity entity) {
		
		Map<String, Object> map = service.selectBynameByregexp(entity);
		return map;
	}
	

	
	
}
